﻿
// Condition: Write a program that fills and prints a matrix of size (n,n) with particular structure.

using System;



class Matrix_Var3
{
    static void Main()
    {
        // 1.initial statements
        Console.Write("Enter the size of square matrix, n= ");
        int n = int.Parse(Console.ReadLine());
        int count = 1;
        int[,] matrix = new int[n, n];


        // 2. 
        // 2.1 First we define the elements of column and row with index 0.
        // 2.1.1 elements of column[0]
        matrix[n - 1, 0] = 1;
        for (int row  = n-2; row  >= 0; row --)
        {
            int col = 0;
            matrix[row, col] = matrix[row+1,col]+count;
            count++;
        }

        // 2.1.2 elements of row[0]

        for (int col  = 1; col<n; col ++)
        {
            int row = 0;
            matrix[row, col] = matrix[row, col - 1] + count;
            count--;
        }

        // 2.2 find all other elements of matrix

        for (int row = 0; row < n-1; row++)
        {
            for (int col = 0; col < n-1; col++)
            {
                matrix[row + 1, col + 1] = matrix[row, col] + 1;
            }
        }
       


        // 3. print the matrix[n,n]

        for (int row = 0; row < n; row++)
        {
            for (int col = 0; col < n; col++)
            {
                Console.Write(matrix[row, col] + " ");
            }
            Console.WriteLine();
        }
        Console.WriteLine();


    }
}

